/**
 * sysTradeLogServiceImpl
 * 项目名称:分秒金融
 *
 * @author lunli
 *
 * 功能描述:平台交易管理
 * 
 * 历史版本:2017-05-09 v1.0.0 lunli  创建:
 * 
 */
package com.fmjr.sys.sysTradeLog.service.impl;

import com.fmjr.common.base.exception.BusinessException;
import com.fmjr.common.base.util.Pager;
import com.fmjr.common.util.SqlUtil;
import com.fmjr.sys.sysTradeLog.bean.SysTradeLog;
import com.fmjr.sys.sysTradeLog.dao.SysTradeLogDao;
import com.fmjr.sys.sysTradeLog.service.ISysTradeLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


@Service("sysTradeLogService")
public class  SysTradeLogServiceImpl implements ISysTradeLogService {
	

	@Autowired
    private SysTradeLogDao sysTradeLogDao;

	/**
	 * 根据条件查询平台交易记录
	 * @author lunli
	 * @param  pager
	 * @return SysTradeLogList
	 * @throws BusinessException
	 */
	public void selectSysTradeLogList(Pager<SysTradeLog> pager) throws BusinessException{
		int totalCount = sysTradeLogDao.selectSysTradeLogCount(pager);
		int numPerPage = SqlUtil.checkPageSize(pager.getNumPerPage());
		int currentPage = SqlUtil.checkPageCurrent(totalCount, numPerPage, pager.getPageNum());
		pager.setLimitStart(SqlUtil.countOffset(currentPage, numPerPage));
		pager.setPageSize(numPerPage);
		pager.setCurrentPage(currentPage);
		pager.setTotalCount(totalCount);
		pager.setTotalPage(totalCount%numPerPage==0?totalCount/numPerPage:totalCount/numPerPage+1);
		List<SysTradeLog> list = sysTradeLogDao.selectSysTradeLogList(pager);
		pager.setList(list);
	}
	
	/**
	 * 根据ID查询平台交易记录
	 * @author lunli
	 * @param id
	 * @return domain
	 * @throws BusinessException
	 */
	public SysTradeLog selectSysTradeLogById(Long id) throws BusinessException{
		return sysTradeLogDao.selectSysTradeLogById(id);
	}

	/**
	 *  删除平台交易记录
	 * @author lunli	 
	 * @param id
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int deleteSysTradeLogById(Long id) throws BusinessException{
		return sysTradeLogDao.deleteSysTradeLogById(id);
	}
	
	/**
	 * 修改平台交易记录
	 * @author lunli
	 * @param sysTradeLog
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int updateSysTradeLog(SysTradeLog sysTradeLog) throws BusinessException{
		return sysTradeLogDao.updateSysTradeLogSelective(sysTradeLog);
	}

	/**
	 * 新增平台交易记录
	 * @author lunli
	 * @param sysTradeLog
	 * @return
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int createSysTradeLog(BigDecimal affactMoney, String logType, String paymentType, Long incomeMemberId,
			Long outMemberId, String logOrder, String logRemark) throws BusinessException {
		SysTradeLog sysTradeLog = new SysTradeLog();
		sysTradeLog.setAffactMoney(affactMoney);
		sysTradeLog.setCreateDate(new Date());
		sysTradeLog.setIncomeMemberId(incomeMemberId);
		sysTradeLog.setLogOrder(logOrder);
		sysTradeLog.setLogRemark(logRemark);
		sysTradeLog.setLogType(logType);
		sysTradeLog.setOutMemberId(outMemberId);
		sysTradeLog.setPaymentType(paymentType);
		return sysTradeLogDao.createSysTradeLog(sysTradeLog);
	}
	

	

}
